package jp.seraph.jsade.util;

import java.util.HashMap;
import java.util.Map;

import jp.seraph.jsade.effector.DefaultEffector;
import jp.seraph.jsade.effector.Effector;
import jp.seraph.jsade.effector.EffectorKind;
import jp.seraph.jsade.effector.NaoEffector;
import jp.seraph.jsade.effector.NaoEffectorKind;
import jp.seraph.jsade.message.MessageUtil;
import jp.seraph.jsade.model.Joint;
import jp.seraph.jsade.sexpression.DefaultLeaf;
import jp.seraph.jsade.sexpression.DefaultNode;

/**
 * Nao用エフェクタの生成器<br>
 * 基本的に内部的に使用する
 */
public class NaoEffectorCreator implements EffectorCreator {
    public NaoEffectorCreator(){

    }

    /**
     * ジョイント名 -> エフェクタ名へのマッピング
     */
    private static final Map<String, NaoEffectorKind> EFFECTOR_NAME_MAP;
    static{
        EFFECTOR_NAME_MAP = new HashMap<String, NaoEffectorKind>();
        EFFECTOR_NAME_MAP.put("hj1", NaoEffectorKind.HE1);
        EFFECTOR_NAME_MAP.put("hj2", NaoEffectorKind.HE2);

        EFFECTOR_NAME_MAP.put("llj1", NaoEffectorKind.LLE1);
        EFFECTOR_NAME_MAP.put("rlj1", NaoEffectorKind.RLE1);
        EFFECTOR_NAME_MAP.put("llj2", NaoEffectorKind.LLE2);
        EFFECTOR_NAME_MAP.put("rlj2", NaoEffectorKind.RLE2);
        EFFECTOR_NAME_MAP.put("llj3", NaoEffectorKind.LLE3);
        EFFECTOR_NAME_MAP.put("rlj3", NaoEffectorKind.RLE3);
        EFFECTOR_NAME_MAP.put("llj4", NaoEffectorKind.LLE4);
        EFFECTOR_NAME_MAP.put("rlj4", NaoEffectorKind.RLE4);
        EFFECTOR_NAME_MAP.put("llj5", NaoEffectorKind.LLE5);
        EFFECTOR_NAME_MAP.put("rlj5", NaoEffectorKind.RLE5);
        EFFECTOR_NAME_MAP.put("llj6", NaoEffectorKind.LLE6);
        EFFECTOR_NAME_MAP.put("rlj6", NaoEffectorKind.RLE6);

        EFFECTOR_NAME_MAP.put("laj1", NaoEffectorKind.LAE1);
        EFFECTOR_NAME_MAP.put("raj1", NaoEffectorKind.RAE1);
        EFFECTOR_NAME_MAP.put("laj2", NaoEffectorKind.LAE2);
        EFFECTOR_NAME_MAP.put("raj2", NaoEffectorKind.RAE2);
        EFFECTOR_NAME_MAP.put("laj3", NaoEffectorKind.LAE3);
        EFFECTOR_NAME_MAP.put("raj3", NaoEffectorKind.RAE3);
        EFFECTOR_NAME_MAP.put("laj4", NaoEffectorKind.LAE4);
        EFFECTOR_NAME_MAP.put("raj4", NaoEffectorKind.RAE4);
    }

    /**
     * 対象ジョイントを角速度aAngularVelocityに設定するエフェクタを作成する
     *
     * @param aJoint
     * @param aAngularVelocity
     * @return
     */
    public Effector createJointEffector(Joint aJoint, double aAngularVelocity){
        if(EFFECTOR_NAME_MAP.containsKey(aJoint.getName()))
            return new NaoEffector(new DefaultNode(new DefaultLeaf(EFFECTOR_NAME_MAP.get(aJoint.getName()).toString()), new DefaultLeaf(Double.toString(aAngularVelocity))));
        else
            throw new IllegalArgumentException(MessageUtil.matchedEffectorNotFound(aJoint.getName()));
    }

    /**
     *
     * @see jp.seraph.jsade.util.EffectorCreator#createBeamEffector(double, double, double)
     */
    public Effector createBeamEffector(double aX, double aY, double aZ) {
        return new DefaultEffector(NaoEffectorKind.BEAM, aX, aY, aZ);
    }

    /**
     *
     * @see jp.seraph.jsade.util.EffectorCreator#createEffector(jp.seraph.jsade.effector.EffectorKind, double)
     */
    public Effector createEffector(EffectorKind aKind, double aValue) {
        return new DefaultEffector(aKind, aValue);
    }

    /**
     *
     * @see jp.seraph.jsade.util.EffectorCreator#createSayEffector(java.lang.String)
     */

    public Effector createSayEffector(String aMessage) {
        return new DefaultEffector(NaoEffectorKind.SAY, aMessage);
    }
}
